<?php
/**
 * XmuSlh, web platform of Student Association Federation of Xiamen University
 * 
 * Rewritting one or some pages of StatusNet. 
 * To get the original version, please visit <http://status.net/>.
 * 
 * StatusNet, the distributed open-source microblogging tool
 * 
 * LICENCE: This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * The action to get the json data.
 * 
 * 从特定Action中取得json格式的Api入口
 * 
 * @author		ytukie <ytukie@gmail.com>
 * @version		0.4
 * 
 * 0.2)  Updates the $code, make it could display Chinese correctly.
 * 0.3)  Adds the 'jsondata'.
 * 0.4)  Changes the original wrong way to treat the Chinese.
 */

// XmuSlh only.
if ( !defined('XMUSLH')) { exit(1); }

require_once INSTALLDIR . '/lib/slh_action.php';
require_once INSTALLDIR . '/lib/slh_util.php';

class JsonAction extends Action
{
	/**
	 * The json data array.
	 */
	var $jsondata = array();
	
	/**
	 * Callback function?
	 */
	//var $callback		= null;
	
	/**
	 * Handle a request.
	 */
	function hanlde($args)
	{
		parent::handle($args);
		
		header('Access-Control-Allow-Origin: *');
		header('Content-Type: application/json; charset=utf-8');
	}
	
	/**
	 * Constructs a data in json format.
	 */
	function showJson()
	{
		/*
		// Check for JSONP callback
		if (isset($this->callback)) {
			print $this->callback . '(';
		}*/
		
		$code = urldecode(json_encode($this->jsondata));
		print($code);
		
		/*
		// endDocument(json).
		if (isset($this->callback)) {
			print ')';
		}*/
	}
}

?>